package com.anis.project.medcare.command.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.ui.PartInitException;

import com.anis.jpa.medical.model.Patient;
import com.anis.project.medcare.Activator;
import com.anis.project.medcare.editors.PatientEditor;
import com.anis.project.medcare.editors.input.PatientEditorInput;

public class NewPatient implements IHandler {

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Patient patient = new Patient();
		PatientEditorInput patientEditorInput = new PatientEditorInput(patient);
		try {
			Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
					.getActivePage()
					.openEditor(patientEditorInput, PatientEditor.ID);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean isEnabled() {
		return Activator.getDefault().isConnectiontoDB();
	}

	@Override
	public boolean isHandled() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {
		// TODO Auto-generated method stub

	}

}
